using Unity.Burst;
using Unity.Entities;
using Unity.Mathematics;
using UnityEngine;

partial struct PlayerControlSystem : ISystem
{
    [BurstCompile]
    
    public void OnCreate(ref SystemState state)
    {
        state.RequireForUpdate<PlayerControlComponent>();
    }

    [BurstCompile]
    public void OnUpdate(ref SystemState state)
    {
        var player = SystemAPI.GetSingletonEntity<PlayerControlComponent>();
        var mc = SystemAPI.GetComponentRW<MoveComponent>(player);
        float h = Input.GetAxis("Horizontal");
        float v = Input.GetAxis("Vertical");
        if (h != 0 || v != 0)
        {
            mc.ValueRW.dir=new float3(h,v,0);
            mc.ValueRW.speed=2f;
        }else{
            mc.ValueRW.dir=default;
            mc.ValueRW.speed=0f;
        }
    }

    [BurstCompile]
    public void OnDestroy(ref SystemState state)
    {
        
    }
}
